# -*- coding: utf-8 -*-
"""
Created on Wed Jul 22 18:24:14 2020

@author: Colleen
"""


# import os,sys,shutil
# old_dir = '..\\audio\\kaggle_data\\train\\audio'
# new_dir = 'data\\test_10'
#
# #创建新的test
# old_dir_list = os.listdir(old_dir)
# old_length = len(os.listdir(old_dir))
# for dir in os.listdir(old_dir):
#     audio_dir = os.path.join(old_dir, dir)
#     audio_dir_list = os.listdir(audio_dir)
#     for j in range(1500,1550):
#         audio_before_dir = os.path.join(audio_dir,audio_dir_list[j])
#         name = dir + '_' + str(j) + '.wav'
#         new_name_dir = os.path.join(audio_dir,name)
#         try:
#             os.rename(audio_before_dir, new_name_dir)
#         except:
#             continue
#         #new_audio_dir = os.path.join(new_dir, name)
#         shutil.copy(new_name_dir,new_dir)


#创建新的train
import os,sys,shutil 
old_dir = '..\\audio\\kaggle_data\\train\\audio'
new_dir = 'data\\train_2000'

order = ['yes', 'no', 'up', 'down', 'left', 'right', 'on', 'off', 'stop', 'go']

old_dir_list = os.listdir(old_dir)
old_length = len(os.listdir(old_dir)) 
for file_name in old_dir_list:
    os.mkdir(os.path.join(new_dir,file_name))
    old_file_dir = os.path.join(old_dir, file_name)
    file_list = os.listdir(old_file_dir)
    if file_name in order:
        for i in range(2300):#命令数据集比较多
            file_wav_name = file_list[i]
            old_name_dir = os.path.join(old_file_dir, file_wav_name)
            new_wav_dir = os.path.join(new_dir, file_name)
            shutil.copy(old_name_dir, new_wav_dir)
    else:
        for i in range(1700):
            file_wav_name = file_list[i]
            old_name_dir = os.path.join(old_file_dir, file_wav_name)
            new_wav_dir = os.path.join(new_dir, file_name)
            shutil.copy(old_name_dir, new_wav_dir)
        
#创建数据集
old_dir = '..\\audio\\kaggle_data\\train\\audio'
new_dir = 'data\\test_shengxia'

order = ['yes', 'no', 'up', 'down', 'left', 'right', 'on', 'off', 'stop', 'go']

old_dir_list = os.listdir(old_dir)
old_length = len(os.listdir(old_dir)) 
for file_name in old_dir_list:
    os.mkdir(os.path.join(new_dir,file_name))
    old_file_dir = os.path.join(old_dir, file_name)
    file_list = os.listdir(old_file_dir)
    if file_name in order:
        for i in range(2300,len(file_list)):#命令数据集比较多
            file_wav_name = file_list[i]
            old_name_dir = os.path.join(old_file_dir, file_wav_name)
            new_wav_dir = os.path.join(new_dir, file_name)
            shutil.copy(old_name_dir, new_wav_dir)
    else:
        for i in range(1700,len(file_list)):
            file_wav_name = file_list[i]
            old_name_dir = os.path.join(old_file_dir, file_wav_name)
            new_wav_dir = os.path.join(new_dir, file_name)
            shutil.copy(old_name_dir, new_wav_dir)